"use strict";

var Router = require('koa-router');
var config = require('../../../config/config.js');
var daoDispatcher = require('../../../dao/user.js');

console.log('router:' + config.baseUrl + '/v2/user');

var router = new Router({
    prefix: config.baseUrl + '/v2/user'
});
module.exports = router.routes();

router.get('/test', function*() {
    this.body = 'test work fine';
});


/**
 * post /api/v2/user/
 {
     "email": "abc@abc.com",
     "password": "abc",
     "name": "abc",
     "role":"超级管理员"
 }
 */
router.post('/', function*() {
    var json = this.request.inParams;
    if (!json.role) {
        json.role = '普通用户';
    }
    var result = yield daoDispatcher.addOne(this.request.inParams);
    this.body = result;
});

/**
 * post /api/v2/user/check
 {
    "email":"xx",
    "password":"xxx"
 }
 * @param json
 */
router.post('/check', function*() {
    var result = yield daoDispatcher.check(this.request.inParams);
    this.body = result;
});